package tools;

import java.util.Vector;

public class timetool {
	public timetool() {
		
	}
	
	public static int calculate(Vector<String> time) {
		int sum=0;
		for(int i=0;i<time.size()-1;i++) {
		String start=time.get(i);
		String end=time.get(i+1);
		String para1[]=start.split(":");
		String para2[]=end.split(":");
		int starthour=Integer.parseInt(para1[0]);
		int endhour=Integer.parseInt(para2[0]);
		int startminute=Integer.parseInt(para1[1]);
		int endminute=Integer.parseInt(para2[1]);
		if(starthour==endhour) {
			sum+=endminute-startminute;
		}
		else if(starthour<endhour) {
			for(int j=starthour;j<endhour-1;j++) {
				sum+=60;
				
			}
			sum+=60-startminute+endminute;
		}
		else if(starthour>endhour) {
			sum+=60-startminute;
			for(int j=starthour+1;j<24;j++) {
				sum+=60;
			}
			for(int j=0;j<=endhour-1;j++) {
				sum+=60;
			}
			sum+=endminute;
		}
		}return sum;}
		
	
	
	public static int Singlecalculate(String start,String end) {
		int sum=0;
		String para1[]=start.split(":");
		String para2[]=end.split(":");
		int starthour=Integer.parseInt(para1[0]);
		int endhour=Integer.parseInt(para2[0]);
		int startminute=Integer.parseInt(para1[1]);
		int endminute=Integer.parseInt(para2[1]);
	//	System.out.println(starthour+" "+endhour+" "+startminute+" "+endminute);
		if(starthour==endhour) {
		//	System.out.println(endminute-startminute);
			sum+=endminute-startminute;	
		}
		else if(starthour<endhour) {
			for(int j=starthour;j<endhour-1;j++) {
				sum+=60;
			}
			sum+=60-startminute+endminute;
		}
		return sum;
	}
	
	public static boolean compare(String time1,String time2) {
		String 	firsthour,firstminute;
		String	secondhour,secondminute;
		String para1[]=time1.split(":");
		String para2[]=time2.split(":");
		firsthour=para1[0];firstminute=para1[1];
		secondhour=para2[0];secondminute=para2[1];
		if(Integer.parseInt(firsthour)<Integer.parseInt(secondhour)) return true;
		else if(Integer.parseInt(firsthour)==Integer.parseInt(secondhour)) {
			if(Integer.parseInt(firstminute)<Integer.parseInt(secondminute)) return true;
			else return false;
		}
		else return false;
	}
	
	public static String backclock(int time) {
		String realtime="";
		int hour=time/60;
		if(hour==0) return "00:"+time%60;
		else if(hour>0&&hour<10) {
			realtime+="0"+hour+":";
			int mintue=time%60;
			if(mintue<10) realtime+="0"+mintue;
			else realtime+=mintue;
		}
		else if(hour>=10) {
			realtime+=hour+":";
			int mintue=time%60;
			if(mintue<10) realtime+="0"+mintue;
			else realtime+=mintue;
		}
		return realtime;
	}
	public static int backminutes(String time) {
		String para[]=time.split(":");
		int hour=Integer.parseInt(para[0]);
		int minute=Integer.parseInt(para[1]);
		return hour*60+minute;
	}
}
